//
//  GTGTUserCenterVC.m
//  globalTranslate
//
//  Created by 陈镇 on 2025/8/11.
//

#import "GTUserCenterVC.h"
#import "GTGTUserCenterHeaderView.h"
#import "SLWebViewController.h"
#import "CZSelectFontSizeView.h"



@interface GTUserCenterVC ()<GTGTUserCenterHeaderViewDelegate>

@property(nonatomic,strong) NSArray *dataArray;
@property(nonatomic,strong) GTGTUserCenterHeaderView *header;
@end

@implementation GTUserCenterVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    self.title = @"用户中心";
    
    
    self.tableView.tableHeaderView = self.header;
    
    self.header.model = [SLUserInfoModel shareManage];
}

-(GTGTUserCenterHeaderView *)header{
    if (!_header) {
        _header = [[GTGTUserCenterHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
        _header.delegate = self;
    }
    return _header;
}
-(NSArray *)dataArray{
    if (!_dataArray) {
        _dataArray = @[@"用户协议",@"隐私协议",@"版本号",@"字体大小"];
    }
    return _dataArray;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    QMUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    NSString *title = self.dataArray[indexPath.row];
    
    if (!cell) {
        cell = [[QMUITableViewCell alloc] initForTableView:tableView withReuseIdentifier:@"cell"];
        
        cell.backgroundColor = UIColorWhite;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
        cell.textLabel.textColor = UIColorHex(#232323FF);
        cell.textLabel.font = SLFontMakeMedium(16);
        
        UIImageView *imageVIew = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
        imageVIew.image = [UIImage imageNamed:@"next"];
        cell.accessoryView = imageVIew;
        
        cell.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
            
    }
    
    if ([title isEqualToString:@"版本号"]) {
        QMUILabel *text = [QMUILabel createTextColor:UIColorHex(999999) font:SLFontMakeRegular(14) textAlignment:NSTextAlignmentRight];
        text.text = [NSString stringWithFormat:@"v%@",SL_SYS_CLIENTVER];
        text.frame = CGRectMake(10, 0, 80, 14);
        cell.accessoryView = text;
        
        cell.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    }
    if ([title isEqualToString:@"字体大小"]) {
        CZSelectFontSizeView *text = [[CZSelectFontSizeView alloc] initWithFrame:CGRectMake(0, 0, 100, 37)];
//        text.backgroundColor = UIColorTestRed;
        cell.accessoryView = text;
        
    }
    
    cell.textLabel.text = title;
    return cell;
    
}

-(void)userCenterHeaderViewClickItem:(NSInteger)index{
    
    [self.navigationController popViewControllerAnimated:NO];
    if (index == 1 || index == 2) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeTranslateType" object:@(index)];
    }else{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeTranslateType" object:@(index)];
        });
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        SLWebViewController *web = [[SLWebViewController alloc] initWithUrl:@"https://www.freeprivacypolicy.com/live/a5df0000-c4e1-4ee0-9fd2-6db9a3f4475c"];
        [CurrentVC.navigationController pushViewController:web animated:YES];
    }else if (indexPath.row == 1) {
        SLWebViewController *web = [[SLWebViewController alloc] initWithUrl:@"https://www.freeprivacypolicy.com/live/a5df0000-c4e1-4ee0-9fd2-6db9a3f4475c"];
        [CurrentVC.navigationController pushViewController:web animated:YES];
    }
}


/*
 用户协议：https://sites.google.com/view/gotranslate72328/privacy-policy

 隐私协议：https://www.freeprivacypolicy.com/live/a5df0000-c4e1-4ee0-9fd2-6db9a3f4475c

 支持网站：https://www.freeprivacypolicy.com/live/a5df0000-c4e1-4ee0-9fd2-6db9a3f4475c
 */
@end
